package com.yayohos.locationmanager;

import com.yayohos.locationmanager.base.LocationBaseAbility;
import com.yayohos.locationmanager.configuration.Configurations;
import com.yayohos.locationmanager.configuration.LocationConfiguration;
import com.yayohos.locationmanager.helper.LogUtils;

import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.location.Location;

/**
 * 再Ability中定位
 */
public class SampleAbility extends LocationBaseAbility implements SamplePresenter.SampleView {
    private SamplePresenter samplePresenter;
    private Text text;
    private Button do_location;

    @Override
    public LocationConfiguration getLocationConfiguration() {
        return Configurations.defaultConfiguration("Give me the permission!", "Would you mind to turn GPS on?");
    }


    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_ability_sample);
        text = (Text) findComponentById(ResourceTable.Id_text_helloworld);
        do_location = (Button) findComponentById(ResourceTable.Id_do_location);
        do_location.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                getLocation();
            }
        });
        samplePresenter = new SamplePresenter(this);
    }

    @Override
    public String getText() {
        return text.getText();
    }

    @Override
    public void setText(String text1) {
        LogUtils.logI("setText++" + Thread.currentThread().getName());
        text.setText(text1);
    }


    @Override
    public void updateProgress(String text) {
        LogUtils.logI("updateProgress=" + text);
    }

    @Override
    public void dismissProgress() {
        LogUtils.logI("dismissProgress=");
    }

    @Override
    public void onLocationChanged(Location location) {
        samplePresenter.onLocationChanged(location);
    }

    @Override
    public void onLocationFailed(int type) {
        samplePresenter.onLocationFailed(type);
    }

    @Override
    protected void onStop() {
        super.onStop();
        samplePresenter.destroy();
    }
}
